Skip to content

Make gen more strict about being called exactly once#8

Open
TomiBelan wants to merge 3 commits intocreationix:masterfrom
TomiBelan:master
Open

Make gen more strict about being called exactly once#8
TomiBelan wants to merge 3 commits intocreationix:masterfrom
TomiBelan:master

Conversation

@TomiBelan
Copy link
Copy Markdown
Contributor

This pull request is branched off from #7. You probably want to look at 0eeee5f, not the combined diff of both this and #7. If you want to merge it without #7, tell me and I'll rebase it.

What this commit does, and why:

  • Protects against errors caused by incorrect usage. Correct library clients should be mostly unaffected. Ensures that gen is called at most once before the generator yields, and if it is not called, the generator has to yield a continuable.
  • Fixes yielding weird async functions that receive a callback, but return a function value. Imagine a hypothetical setTimeout that doesn't return an integer, but a function that cancels the timeout when called. Yeah, I've never seen one either, this was mostly a side effect...
  • Renames "resume" to "gen", to follow the README. The idea is that "resume" is what the anonymous function returned by "gen" is called. If you don't like the rename, I can separate it from the rest of the commit.
  • Modifies tests so that they don't use gen()(null, value). You're not supposed to do that: it circumvents the done check in resume. The new checks correctly detected that the tests didn't call gen before yielding nor yield a continuable.
  • Removes useless yielded = true line from check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant